package com.mdd.admin.controller.yylq;

import com.mdd.admin.service.yylq.ITAppCityService;
import com.mdd.admin.service.yylq.ITAppDicService;
import com.mdd.admin.service.yylq.ITAppProvinceService;
import com.mdd.admin.service.yylq.ITAppTownService;
import com.mdd.common.aop.NotLogin;
import com.mdd.common.aop.NotPower;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.entity.yangyangLeadingEnterprise.TAppDic;
import com.mdd.common.entity.yangyangLeadingEnterprise.common.JsonReturn;
import com.mdd.common.util.aliyunOss.OssUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/adminapi/yylq/common")
@Api(tags = "羊羊领企----公共方法管理")
public class CommonUtilController {

    @Resource
    private OssUtil ossUtil;

    @Resource
    ITAppProvinceService appProviceService;

    @Resource
    ITAppCityService  appCityService;

    @Resource
    ITAppTownService  appTownService;

    @Resource
    ITAppDicService  appDicService;

    @NotLogin
    @NotPower
    @ApiIgnore
    @PostMapping(value = "/upload",  produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String uploadFile(@RequestParam("file") MultipartFile file) {
        String url = ossUtil.uploadFile(file, "backgroundManagement/uploads/");
        return JsonReturn.success().put("url", url).toJsonStr();
    }


//    @PostMapping("/selectProviceList")
//    @ApiOperation(value="省份下拉列表")
//    public String selectProviceList() {
//        List<TAppProvince> list =appProviceService.selectProviceList();
//        return JsonReturn.success().setListData(Optional.ofNullable(list).orElse(new ArrayList<>())).toJsonStr();
//    }

//    /**
//     * 省份下拉列表
//     * @return
//     */
//    @NotLogin
//    @PostMapping(value = "/selectProviceList",produces = "application/json; charset=UTF-8")
//    @ApiOperation(value="省份下拉列表")
//    @ResponseBody
//    public AjaxResult<PageResult<TAppProvince>> selectProviceList() {
//        List<TAppProvince> list =appProviceService.selectProviceList();
//
//        PageResult<TAppProvince> pageResult = new PageResult<>();
//        pageResult.setLists(Optional.ofNullable(list).orElse(new ArrayList<>()));
//        return AjaxResult.success(pageResult);
//    }

//    @PostMapping("/selectCityList")
//    @ApiOperation(value="市下拉列表")
//    public String selectCityList(Integer provinceId) {
//        List<TAppCity> list =appCityService.selectCityList(provinceId);
//        return JsonReturn.success().setListData(Optional.ofNullable(list).orElse(new ArrayList<>())).toJsonStr();
//    }

//    /**
//     * 省份下拉列表
//     * @return
//     */
//    @NotLogin
//    @PostMapping(value = "/selectCityList",produces = "application/json; charset=UTF-8")
//    @ApiOperation(value="市下拉列表")
//    @ResponseBody
//    public AjaxResult<PageResult<TAppCity>> selectCityList(Integer provinceId) {
//        List<TAppCity> list =appCityService.selectCityList(provinceId);
//
//        PageResult<TAppCity> pageResult = new PageResult<>();
//        pageResult.setLists(Optional.ofNullable(list).orElse(new ArrayList<>()));
//        return AjaxResult.success(pageResult);
//    }
//
//    @PostMapping("/selectTownList")
//    @ApiOperation(value="区/乡镇下拉列表")
//    public String selectTownList(Integer cityId) {
//        List<TAppTown> list =appTownService.selectTownList(cityId);
//        return JsonReturn.success().setListData(Optional.ofNullable(list).orElse(new ArrayList<>())).toJsonStr();
//    }

//    /**
//     * 字典表根据类型(下拉列表)查询list
//     * @param type
//     * @return
//     */
//    @NotLogin
//    @PostMapping(value = "/selectDicListByType",produces = "application/json; charset=UTF-8")
//    @ApiOperation(value="字典表根据类型(下拉列表)查询list")
//    @ResponseBody
//    public String selectDicListByType(String type) {
//        List<TAppDic> list=appDicService.selectDicListByType(type);
//        return JsonReturn.success().setListData(Optional.ofNullable(list).orElse(new ArrayList<>())).toJsonStr();
//    }

    /**
     * 字典表根据类型(下拉列表)查询list
     * @param type
     * @return
     */
    @NotLogin
    @PostMapping(value = "/selectDicListByType",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="字典表根据类型(下拉列表)查询list")
    @ResponseBody
    public AjaxResult<PageResult<TAppDic>> selectDicListByType(String type) {
        List<TAppDic> list=appDicService.selectDicListByType(type);

        PageResult<TAppDic> pageResult = new PageResult<>();
        pageResult.setLists(Optional.ofNullable(list).orElse(new ArrayList<>()));
        return AjaxResult.success(pageResult);
    }






}
